from tortoise import fields
from .base import BaseModel, TimestampMixin

class Content(BaseModel, TimestampMixin):
    title = fields.CharField(max_length=255,description="标题")
    order = fields.IntField(default=0, description="排序")
    type = fields.IntField(default=1, description="类型1图文2视频", index=True)
    cover = fields.CharField(max_length=255, description="封面")
    tags = fields.JSONField(null=True, description="标签")
    parent = fields.ForeignKeyField('models.ContentCategory',description="分类id", related_name='content_parent', null=True,on_delete=fields.NO_ACTION)
    desc = fields.TextField(null=True, description="备注")
    files = fields.JSONField( null=True, description="多文件")
    go_type = fields.IntField(default=0, description="跳转类型")
    go_url = fields.CharField(max_length=255,null=True, description="跳转值")
    shop_ids = fields.CharField(max_length=255, description="关联商品")
    state = fields.BooleanField(default=True, description="是否激活")
    class Meta:
        table = "content_list"

class ContentCategory(BaseModel, TimestampMixin):
    name = fields.CharField(max_length=20, description="分类名称")
    desc = fields.CharField(max_length=500, null=True, blank=True, description="备注")
    is_deleted = fields.BooleanField(default=False, description="软删除标记", index=True)
    order = fields.IntField(default=0, description="排序", index=True)
    parent_id = fields.IntField(default=0, max_length=10, description="父分类ID", index=True)

    class Meta:
        table = "content_category"